using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameVuTru.ManagerScreens;
using GameVuTru.ResourceManager;
namespace GameVuTru.GameObject
{
    public class Bullet : CObject
    {
        Vector2 speedbullet;
        public BULLETTYPE bulletType;
        float rotation;
        public Bullet(BULLETTYPE type, Vector2 pos)
        {
            speedbullet = new Vector2(0, -8);
            if (type == BULLETTYPE.BULLETBLUE)
            {
                m_sprite = new CSprite(ReSouce.bulletBlue, 1, 1, 10, 30);
            }
            if (type == BULLETTYPE.BULLETRED)
            {
                m_sprite = new CSprite(ReSouce.bulletRedsmall, 4, 4, 64, 13);
            }
            if (type == BULLETTYPE.BULLETENEMY)
            {
                m_sprite = new CSprite(ReSouce.BulletEnemy, 20, 20, 400, 20);
            }
       
            postion = pos;
            Isvisible = true;
            rotation = 0f;
            bulletType = type;
            typeobject = OBJECTTYPE.BULLET;
        }
        public Bullet(BULLETTYPE type, Vector2 pos, float rota, Vector2 vecloc)
        {
            if (type == BULLETTYPE.BULLETBLUE)
            {
                m_sprite = new CSprite(ReSouce.bulletBlue, 1, 1, 10, 30);
            }
            if (type == BULLETTYPE.BULLETRED)
            {
                m_sprite = new CSprite(ReSouce.bulletRedsmall, 4, 4, 64, 13);
            }
            if (type == BULLETTYPE.BULLETENEMY)
            {
                m_sprite = new CSprite(ReSouce.BulletEnemy, 20, 20, 400, 20);
            }
            speedbullet = vecloc;
            rotation = rota;
            postion = pos;
            bulletType = type;
            Isvisible = true;
            typeobject = OBJECTTYPE.BULLET;
        }
        //ham nay janh rieng cho dan do
        public Bullet(BULLETTYPE type, Vector2 pos, int size)
        {
            if (size == 1)
            {
                m_sprite = new CSprite(ReSouce.bulletRedsmall, 1, 1, 10, 30);
            }
            if (size == 2)
            {
                m_sprite = new CSprite(ReSouce.bulletRedmedium, 1, 1, 15, 45);
            }
            if (size == 3)
            {
                m_sprite = new CSprite(ReSouce.bulletRedbig, 1, 1, 20, 60);
            }
            speedbullet = new Vector2(0, -10);
            rotation = 0f;
            postion = pos;
            bulletType = type;
            Isvisible = true;
            typeobject = OBJECTTYPE.BULLET;
        }
        public override void Update(GameTime gametime)
        {
            if (isvisible)
            {
                base.Update(gametime);

                if (postion.Y < -10 || postion.Y > 480)
                {
                    isvisible = false;
                }
                postion += speedbullet;
                if (bulletType == BULLETTYPE.BULLETBLUE)
                {
                    m_sprite.UpdateSprite(gametime, 0, 0, 1);
                }
                else if (bulletType == BULLETTYPE.BULLETENEMY)
                {
                    m_sprite.UpdateSprite(gametime, 0, 19, 1);
                }
                else if (bulletType == BULLETTYPE.BULLETRED)
                {
                    m_sprite.UpdateSprite(gametime, 0, 0, 1);
                }

            }


        }
        public override void Draw(SpriteBatch sp)
        {
            if (isvisible)
            {
                m_sprite.DrawSprite(sp, postion, rotation);
            }
        }
        public override void UpdateCollion(CObject b)
        {
            base.UpdateCollion(b);
            if (bulletType == BULLETTYPE.BULLETENEMY)
            {

            }
            else
            {
                if (b.typeobject == OBJECTTYPE.ENEMY)
                {
                    Enemy ene = (Enemy)b;
                    if (this.bound.Intersects(b.bound))
                    {
                        this.Isvisible = false;
                        ene.heath -= Player.StrenghtBullet;

                    }
                }
            }

        }
    }
}